#include "game.h"
void init(char arr[ROWS][COLS], char x)
{
	int i = 0;
	int j = 0;
	for (i = 0;i < ROWS;i++)
	{
		for (j = 0;j < COLS;j++)
		{
			arr[i][j] = x;
		}
	}
}
void display(char arr[ROWS][COLS])
{
	int i = 0;
	int j = 0;
	for (j = 0;j <= COL;j++)
	{
		printf("%d ", j);
	}
	printf("\n");
	for (j = 0;j <= COL*2;j++)
	{
		printf("-");
	}
	printf("\n");
	for (i = 1;i <= ROW;i++)
	{
		printf("%d|", i);
		for (j = 1;j <= COL;j++)
		{
			printf("%c ", arr[i][j]);
		}
		printf("\n");
	}
}
void putmine(char arr[ROWS][COLS])
{
	int count = mine_count;
	while (count)
	{
	int x = rand() % 9 + 1;
	int y = rand() % 9 + 1;
		if (arr[x][y] == '0')
		{
			arr[x][y] = '1';
			count--;
		}
	}
}
int is_mine(char mine[ROWS][COLS],char show[ROWS][COLS],int x,int y)
{
	if (mine[x][y] == '0')
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int check_side(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y)
{
	int i = 0;
	int j = 0;
	int count = 0;
	for (i = x - 1;i <= x + 1;i++)
	{
		for (j = y - 1;j <= y + 1;j++)
		{
			if (mine[i][j] == '1')
			{
				count++;
			}
		}
	}
	
	return count;
}
int spread(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y)
{
	int i = 0;
	int j = 0;
	int count = 0;
		for (i = x - 1;i <= x + 1;i++)
		{
			for (j = y - 1;j <= y + 1;j++)
			{
				if (i > 0 && i < 10 && j>0 && j < 10 && show[i][j] == '*' && mine[i][j] == '0')
				{
					if (check_side(mine, show, i, j) == 0)
					{
						show[i][j] = '0';
						spread(mine, show, i, j);
					}
					else
					{
						show[i][j] = check_side(mine, show, i, j) + '0';
					}
				}
			}
		}
}
int is_win(char mine[ROWS][COLS], char show[ROWS][COLS])
{
	int i = 0;
	int j = 0;
	int count = 0;
	for (i = 1;i <= ROW;i++)
	{
		for (j = 1;j <= COL;j++)
		{
			if (show[i][j] != '*')
			{
				count++;
			}
		}
	}
	if (count == 81- mine_count)
	{
		return 0;
	}
	return 1;
}